# -*- coding: UTF-8 -*-
import datetime
import os
from flask import Flask
from flask_sqlalchemy import SQLAlchemy

app = Flask(__name__)
db = SQLAlchemy(app)


class Hosts(db.Model):
    id = db.Column(db.Integer, autoincrement=True, primary_key=True)
    hostname = db.Column(db.String(50))
    ipaddr = db.Column(db.String(50))
    Groups = db.Column(db.String(50))
    Desc = db.Column(db.String(50))
    username = db.Column(db.String(50))
    passwd = db.Column(db.String(50))
    port = db.Column(db.String(50))
    check = db.Column(db.String(10), default="on")

    def to_json(self):
        dict = self.__dict__
        if "_sa_instance_state" in dict:
            del dict["_sa_instance_state"]
        return dict


class scripts(db.Model):
    id = db.Column(db.Integer, autoincrement=True, primary_key=True)
    scriptname = db.Column(db.String(100))
    scripts = db.Column(db.String(2000))
    desc = db.Column(db.String(1000))

    def to_json(self):
        dict = self.__dict__
        if "_sa_instance_state" in dict:
            del dict["_sa_instance_state"]
        return dict


class systems(db.Model):
    id = db.Column(db.Integer, autoincrement=True, primary_key=True)
    username = db.Column(db.String(20))
    password = db.Column(db.String(20))
    name = db.Column(db.String(20))
    Role = db.Column(db.String(20))

    def to_json(self):
        fields = self.__dict__
        if "_sa_instance_state" in fields:
            del fields["_sa_instance_state"]
        return fields


class options(db.Model):
    id = db.Column(db.Integer, autoincrement=True, primary_key=True)
    optvalues = db.Column(db.String(30))
    opttypes = db.Column(db.String(30))
    optdesc = db.Column(db.String(100))

    def to_json(self):
        fields = self.__dict__
        if "_sa_instance_state" in fields:
            del fields["_sa_instance_state"]
        return fields


class Logs(db.Model):
    id = db.Column(db.Integer, autoincrement=True, primary_key=True)
    operator = db.Column(db.String(50))
    runtime = db.Column(db.DateTime, default=datetime.datetime.now())
    scriptname = db.Column(db.String(20))
    script = db.Column(db.String(2000))
    result = db.Column(db.String(20))

    def to_json(self):
        fields = self.__dict__
        if "_sa_instance_state" in fields:
            del fields["_sa_instance_state"]
        return fields


class EntityBase(object):
    def to_json(self):
        fields = self.__dict__
        if "_sa_instance_state" in fields:
            del fields["_sa_instance_state"]
        return fields
